<template>
  <div class="content">
    <div>
      <form-create
        v-model="fapi"
        :rule="rule"
        :option="option"
        @submit="onSubmit"
      ></form-create>
    </div>
  </div>
</template>

<script>
let _this;
export default {
  data() {
    return {
      fapi: null,
      option: {
        "form": {
          "inline": false,
          "labelPosition": "right",
          "size": "small",
          "labelWidth": "105px",
          "hideRequiredAsterisk": false,
          "showMessage": true,
          "inlineMessage": false
        }
      },
      rule: [{
        "type": "input",
        "field": "title",
        "title": "标题",
        "info": "",
        "props": {
          "placeholder": "请输入标题"
        },
        "_fc_drag_tag": "input",
        "hidden": false,
        "display": true
      },
        {
          "type": "input",
          "field": "publisher",
          "title": "发布人",
          "info": "",
          "props": {
            "placeholder": "请输入发布人"
          },
          "_fc_drag_tag": "input",
          "hidden": false,
          "display": true
        },
        {
          "type": "fc-editor",
          "field": "content",
          "title": "内容",
          "info": "",
          "_fc_drag_tag": "fc-editor",
          "hidden": false,
          "display": true,
          "props":{
            config:{
              uploadImgServer:'http://www.free.com/api/Upload/upload',
              uploadFileName:'file',
              height:'600',
            }
          }
        }],

    }
  },
  methods: {
    onSubmit(formData) {
      //todo 提交表单
      _this.createOrUpdate(formData)
    },
    getSchoolHelp: function () {
      _this.$store
        .dispatch("portal/getSchoolHelp")
        .then(() => {
          _this.loading = false;
          _this.dialogVisible = false;
          let data = this.$store.state.portal.schoolHelp;
          if (data) {
            _this.fapi.setValue('title', data.title);
            _this.fapi.setValue('content', data.content);
            _this.fapi.setValue('publisher', data.publisher);
          }
        });
    },
    createOrUpdate: function (param) {
      _this.$store
        .dispatch("portal/createOrUpdateSchoolHelp", {
          id: _this.$store.state.portal.schoolHelp == null ? 0 : _this.$store.state.portal.schoolHelp.id,
          title: param['title'],
          content: param['content'],
          publisher: param['publisher'],
        })
        .then((res) => {
          const {data, msg} = res;
          if (data) {
            _this.$message.success(msg);
          } else {
            _this.$message.error(msg);
            _this.getSchoolDesc();
          }

        });
    },
  },
  created() {
    _this = this;
    _this.getSchoolHelp();
  }
}
</script>

<style scoped lang="scss">
.content {
  padding: 20px;
}
</style>
